<?php
/**
 *
 * @author dzelenika
 *
 */
class groupRights extends bee\form
{ protected static $__formID = "frm2001109060236";
  public $__caption = "Group rights overview ";
  public $__version = "1.1";
  /**
   *
   * @var rightsGrid
   */
  protected $grid;
  protected $arr_group;
  protected $arr_per_den;
  protected $gr_task;
  protected $filter;

  protected $optGroup;
  protected $optPerDen;
  protected $txtFilter;

  public function createForm($evt)
  { $this->gr_task = new bee\gr_task();

    $group = new bee\group();
    $rsGroup = new bee\rowSet(clone $group);
    $this->arr_group = array(-2 => "public", -1 => "all registered");
    bee\factory::save($this->arr_group     += $rsGroup->getList("name", "id"), "arrGroup",       "groupRights");
    bee\factory::save($this->arr_per_den    = bee\getListByRange(3), "arrPermission",  "groupRights");

    $this->txtFilter = new bee\text("filter", $this->filter);
    $this->optGroup = new bee\option("group_id", $this->gr_task->group_id, $this->arr_group, "name");
    $this->optGroup->notSelectedText = "select group";
    $this->optGroup->notSelectedValue = "";

    $this->optPerDen = new bee\option("per_den", $this->gr_task->per_den, $this->arr_per_den);
    $this->optPerDen->notSelectedText = "select permission";
    $this->optPerDen->notSelectedValue = "";

    $this->grid = rightsGrid::getInstance();
    $this->grid->setDataSource(clone $this->gr_task);
  }

  public function loadForm($evt)
  {
  }

  public function drawForm($evt)
  { $this->__DSDoc->setArray(bee\factory::load("arrGroup",       "groupRights"), "group");
    $this->__DSDoc->setArray(bee\factory::load("arrPermission",  "groupRights"), "perden");
  }

  public function grid_filter($evt)
  { $this->filter = $evt["filter"];
    $filter = "%" . $this->filter . "%";
    $afWh = new bee\afterWhere();
    $afWh->text .=   " AND (sys_action like :descr1 OR sys_page like :descr2) ";
    $afWh->setParam("descr1", $filter);
    $afWh->setParam("descr2", $filter);

    $this->gr_task;
    $this->gr_task->fillFromArray($evt, "");
    $this->gr_task->sys_action = "";
    $this->grid->setDataSource($this->gr_task, $afWh);
  }
}

class rightsGrid extends bee\grid
{ public function createGrid($evt)
  { $this->__gridID = "grd201101161604";
    $this->detailFormName = "editGroupRights";
  }
}
